/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package network.packets;

import datamodel.Order3;
import utils.StringUtils;
import utils.Utils;

/**
 *
 * @author Kvest
 */
public class OrderResponce3 extends OrderResponce2
{
    public OrderResponce3(int id)
    {
        super(id);
    }
    
    public OrderResponce3(byte[] data)
    {
        super(ORDER_RESPONCE3);
        order = new Order3(-1);

        parse(data);
    }
    
    protected void parse(byte[] data)
    {
        int offset = 0;

        //Пропускаем название пакета
        byte[] buffer4 = new byte[4];
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length + Utils.byteToInt(buffer4);
        
        parse(data, offset);
    }

    public void createOrder()
    {
        order = new Order3(-1);
    }

    public int parse(byte[] data, int offset)
    {
        byte[] buffer4 = new byte[4];
        
        //partnerID
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        ((Order3)order).setPartnerID(Utils.byteToInt(buffer4));
        
        //partnerName
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length + Utils.byteToInt(buffer4);
        
        //orderShortDesc
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        int strSize = Utils.byteToInt(buffer4);
        byte[] buffer = new byte[strSize];
        System.arraycopy(data, offset, buffer, 0, buffer.length);
        offset += buffer.length;
        ((Order3)order).setOrderShortDesc(StringUtils.bytesToStr(buffer));
        
        //orderFullDesc
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        strSize = Utils.byteToInt(buffer4);
        buffer = new byte[strSize];
        System.arraycopy(data, offset, buffer, 0, buffer.length);
        offset += buffer.length;
        ((Order3)order).setOrderFullDesc(StringUtils.bytesToStr(buffer));
        
        //orderPrelimFullDesc
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        strSize = Utils.byteToInt(buffer4);
        buffer = new byte[strSize];
        System.arraycopy(data, offset, buffer, 0, buffer.length);
        offset += buffer.length;
        ((Order3)order).setOrderPrelimFullDesc(StringUtils.bytesToStr(buffer));
        
        buffer4 = null;
        buffer = null;
        
        return super.parse(data, offset);
    }
}
